package org.test.client.ui.left;

import java.awt.Window;


class OffsetRun implements Runnable{
	private LeftMenuItem item = null;
	private boolean leftOrRigth = true;
	
    private static final int ANIMATION_FRAMES=8;
    private static final int ANIMATION_INTERVAL=20;
    
    private int frameIndex = 0;
	
	public OffsetRun(LeftMenuItem w){
		this(w,true);
	}
	
	
	public OffsetRun(LeftMenuItem w, boolean leftOrRigth) {
		this.item = w;
		this.leftOrRigth = leftOrRigth;
	}


	@Override
	public void run() {
		
		try {
			int rolloverOffset = item.getRolloverOffset();
			int avg = rolloverOffset/ANIMATION_FRAMES;
			for(;frameIndex<ANIMATION_FRAMES;frameIndex++){
				if(leftOrRigth){
					item.setNowOffest(item.getNowOffest()+avg);
				}else{
					item.setNowOffest(item.getNowOffest()-avg);
				}
				
				Thread.sleep(ANIMATION_INTERVAL);
			}
			
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
	}
	
}